package com.ruoyi.socket.probuffer;


import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

public class ProtoServer {


    public static void main(String[] args) throws Exception {

        EventLoopGroup bossGroup = new NioEventLoopGroup();
        EventLoopGroup workerGroup = new NioEventLoopGroup();

        try {
            ServerBootstrap serverBootstrap = new ServerBootstrap();

            // 2.ServerBootstrap 是一个启动 NIO 服务的辅助启动类。你可以在这个服务中直接使用 Channel，
            // 但是这会是一个复杂的处理过程，在很多情况下你并不需要这样做。
            serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                    //
                    .handler(new LoggingHandler(LogLevel.INFO))
                    //.childHandler(new ProtoServerInitializer());
                    .childHandler(new ProtoChannelHandler());

            ChannelFuture channelFuture = serverBootstrap.bind(30005).sync();
            channelFuture.channel().closeFuture().sync();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }

    }
}